package com.googlecode.garbagecan.commons.execstudy;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteWatchdog;

public class Sample2 {

	private static Logger logger = Logger.getLogger(Sample2.class.getName());
	
	public static void main(String[] args) {
		test();
	}
	
	public static void test() {
		CommandLine cmdLine = new CommandLine("sleep");
		cmdLine.addArgument("10");
		
		DefaultExecutor executor = new DefaultExecutor();
		ExecuteWatchdog watchdog = new ExecuteWatchdog(5 * 1000);
		executor.setWatchdog(watchdog);
		
		try {
			int exitValue = executor.execute(cmdLine);
			logger.log(Level.INFO, "Exit Value: " + exitValue);
		} catch (ExecuteException e) {
			logger.log(Level.SEVERE, e.getMessage(), e);
		} catch (IOException e) {
			logger.log(Level.SEVERE, e.getMessage(), e);
		}
	}
}
